import React, {Component} from 'react';
import {Input, message, Button, Form} from 'antd';
import './com_information_update.less';
import {reqCreateCompanyInformation} from '../../api/index'

/*
* 公司信息路由*/

class AddComInformation extends Component {

    state = {
        companyInformation: [],//总的公司信息列表
    }


    //异步获取公司基本信息


    //发异步ajax请求
    componentDidMount() {

    }

    //为第一次render()准备数据
    componentWillMount() {

    }

    submit = (event) => {
        //阻止事件的默认行为
        event.preventDefault()
        //进行表单验证，如果通过了，才发送请求
        this.props.form.validateFields(async (err, values) => {
            if (!err) {
                //1、搜集数据
                    const {name,describe,address,contact,contact_phone}=values
                //请求增加公司信息接口
                const result=await reqCreateCompanyInformation(name,describe,address,contact,contact_phone)
                message.success('增加公司信息成功！')
                this.props.history.push('/com_information')
                //3、根据结果提示
            } else {
                console.log('发送ajax请求失败 ');
            }
        });
    }

    render() {
        //读取状态数据
        const {getFieldDecorator} = this.props.form;

        return (
            <div className="recruit">
                <div><h1>填写公司信息</h1></div>
                <Form layout="inline" onSubmit={this.submit} encType="multipart/form-data">
                    <div className="recruit-style">
                        <div>
                            <Form.Item label="公司名称">
                                {getFieldDecorator('name', {
                                })(<Input className="recruit-style-input"/>)}
                            </Form.Item>
                        </div>
                        <div><Form.Item label="公司介绍">{getFieldDecorator('describe', {
                        })(<Input className="recruit-style-input"/>)}</Form.Item>
                        </div>
                        <div><Form.Item label="公司地址">{getFieldDecorator('address', {
                        })(<Input
                            className="recruit-style-input2"/>)}
                        </Form.Item></div>
                        <div><Form.Item label="联系人">{getFieldDecorator('contact', {
                        })(<Input
                            className="recruit-style-input1"/>)}
                        </Form.Item></div>
                        <div><Form.Item label="联系电话">{getFieldDecorator('contact_phone', {
                        })(<Input
                            className="recruit-style-input2"/>)}
                        </Form.Item></div>
                    </div>
                    <Form.Item>
                        <Button type="primary" htmlType="submit">
                            提交
                        </Button>
                    </Form.Item>
                </Form>
            </div>
        )
    }
}

const WrappedAddComInformation = Form.create()(AddComInformation);
export default WrappedAddComInformation;
